package FIT::Util::IO;

use FIT::Class;
use IO::All -utf8;

subtype 'ReadableFile'
    => as 'IO::All'
    => where { $_->is_file && $_->is_readable }
    => message { "file ($_) is not a readable file" };

subtype 'WritableFile'
    => as 'IO::All'
    => where { $_->is_file && $_->is_writable }
    => message { "file ($_) is not a writable file" };

subtype 'WritableDir'
    => as 'IO::All'
    => where { $_->is_dir && $_->is_writable }
    => message { "file ($_) is not a writable dir" };

coerce($_ => from 'Str' => via { io($_) })
    for qw(ReadableFile WritableFile WritableDir);
